
<style>
  .layui-upload-img{width: 92px; height: 92px; margin: 0 10px 10px 0; border:solid 0.5px #bfbbbb; border-radius: 4px;}
</style>
<div class="layui-form" lay-filter="formAdd" style="padding: 20px 30px 0 0;">
  <div class="layui-form-item">
    <label class="layui-form-label">登录名</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="loginname" value="{{ d.params.loginname || '' }}" lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">图片上传</label>
    <div class="layui-input-inline">
      <div class="layui-upload">
          <button type="button" class="layui-btn" id="test-upload-normal">上传图片</button>
          <div class="layui-upload-list">
            <img class="layui-upload-img" id="test-upload-normal-img">
            <p id="test-upload-demoText"></p>
          </div>
        </div>
    </div>
  </div>

  <!-- <div class="layui-form-item">
    <label class="layui-form-label">手机</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="telphone" value="{{ d.params.telphone || '' }}" lay-verify="phone" placeholder="请输入号码" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">邮箱</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="text" name="email" value="{{ d.params.email || '' }}" lay-verify="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
      </script>
    </div>
  </div> -->
  <div class="layui-form-item">
    <label class="layui-form-label">角色</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <select name="role">
          <option value="0" {{ d.params.role === '管理员' ? 'selected' : '' }}>管理员</option>
          <option value="1" {{ d.params.role === '超级管理员' ? 'selected' : '' }}>超级管理员</option>
          <option value="2" {{ d.params.role === '纠错员' ? 'selected' : '' }}>纠错员</option>
          <option value="3" {{ d.params.role === '采购员' ? 'selected' : '' }}>采购员</option>
          <option value="4" {{ d.params.role === '推销员' ? 'selected' : '' }}>推销员</option>
          <option value="5" {{ d.params.role === '运营人员' ? 'selected' : '' }}>运营人员</option>
          <option value="6" {{ d.params.role === '编辑' ? 'selected' : '' }}>编辑</option>
        </select>
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">审核状态</label>
    <div class="layui-input-inline">
      <script type="text/html" template>
        <input type="checkbox" lay-filter="switch" name="switch" {{ d.params.check ? 'checked' : '' }} lay-skin="switch" lay-text="通过|待审核">
      </script>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label"></label>
    <div class="layui-input-inline">
      <input type="button" lay-submit lay-filter="formSubmit" value="确认" class="layui-btn">
    </div>
  </div>
</div>

<script>
layui.use(['admin', 'form','upload'], function(){
  var $ = layui.$
  ,form = layui.form
  ,upload = layui.upload;

  
  //普通图片上传
  var uploadInst = upload.render({
      elem: '#test-upload-normal'
      ,url: '/upload/'
      ,auto: false//选择文件后不自动上传
      ,before: function(obj){
        //预读本地文件示例，不支持ie8
        // obj.preview(function(index, file, result){
        //   $('#test-upload-normal-img').attr('src', result); //图片链接（base64）
        // });
      }
      //选择文件后的回调
      ,choose: function (obj) {
        obj.preview(function(index, file, result){
          // console.log(index); //得到文件索引
          // console.log(file); //得到文件对象
          // console.log(result); //得到文件base64编码，比如图片
          $('#test-upload-normal-img').attr('src', result);
        })
      }
      ,done: function(res){
        //如果上传失败
        if(res.code > 0){
          return layer.msg('上传失败');
        }
        //上传成功
      }
      ,error: function(){
        //演示失败状态，并实现重传
        var demoText = $('#test-upload-demoText');
        demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
        demoText.find('.demo-reload').on('click', function(){
          uploadInst.upload();
        });
      }
  });
  
});
</script>